/* 
 * File:   MPLSH.h
 * Author: liuyi
 *
 * Created on September 10, 2009, 9:47 PM
 */

#ifndef _MPLSH_H
#define	_MPLSH_H

#include "KNN.h"
#include "Toolkit.h"

using namespace std;

class HashModel;

// refer to paper: Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search
class MPLSH : public KNN {
public:
    void preTrain(int M, int L, float **a, float **b, float W);
    
    void train(vector<Sample *> &sampleList);

    void store2File(const char *modelPath);

    static MPLSH * loadFromFile(const char *modelPath) throw(FileNotFoundException);

    void retrieveNeighbors(vector<Sample *> &neighbors, const Sample &sample);

    void classify(Sample &sample);

    /**
     * classify the input sample, and give the ratio that indicates the proportion of
     * trained samples which have been searched
     */
    float classifyWithSearchRatio(Sample &sample);

    MPLSH(SampleSpace &sampleSpace, bool copyList = true);

    ~MPLSH() {
        releaseModel();
    }

private:

    HashModel *m_hashModel;

    void releaseModel();

    MPLSH();
    MPLSH(const MPLSH &);

};

#endif	/* _MPLSH_H */

